//
//  EditCarTableViewCell.m
//  CarTown
//
//  Created by xionghao on 15/8/26.
//  Copyright (c) 2015年 熊浩. All rights reserved.
//

#import "EditCarTableViewCell.h"
#import "CarlistCellMode.h"
#define kTableTopBorderWidth 10

@interface EditCarTableViewCell ()


@property (weak, nonatomic) IBOutlet UILabel *titlelable;
@property (weak, nonatomic) IBOutlet UIImageView *yanicon;
@property (weak, nonatomic) IBOutlet UILabel *price;
@property (weak, nonatomic) IBOutlet UIImageView *yikoujia;
@property (weak, nonatomic) IBOutlet UILabel *shopname;
@property (weak, nonatomic) IBOutlet UILabel *time;
@property (weak, nonatomic) IBOutlet UIImageView *shoptypeicon;
@property (weak, nonatomic) IBOutlet UILabel *subtitlelable;
@property (weak, nonatomic) IBOutlet UILabel *zhidaoprice;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *width;

@property (weak, nonatomic) IBOutlet UILabel *detail;

@end

@implementation EditCarTableViewCell


+(instancetype)cellWithTableView:(UITableView *)tableview{
    static NSString *CarCell=@"EDCarCell";
    EditCarTableViewCell *cell=[tableview dequeueReusableCellWithIdentifier:CarCell];
    if (cell==nil) {
        [tableview registerNib:[UINib nibWithNibName:NSStringFromClass([self class]) bundle:nil] forCellReuseIdentifier:CarCell];
        cell=[tableview dequeueReusableCellWithIdentifier:CarCell];
    }
    
    return cell;
}

- (IBAction)click:(UIButton *)sender {
    sender.selected=!sender.selected;
}


- (void)awakeFromNib {
    // Initialization code
}
- (IBAction)buttonclick:(UIButton *)sender {
    
    if ([_delegate respondsToSelector:@selector(bottonclickWithCell:withIndex:)]) {
        [_delegate bottonclickWithCell:self withIndex:sender.tag];
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)setIsshowEidt:(BOOL)isshowEidt{
    _isshowEidt=isshowEidt;
    self.editbutton.hidden=isshowEidt;
}
-(void)setFrame:(CGRect)frame{
    frame.origin.y += kTableTopBorderWidth;
    frame.size.height -= kTableTopBorderWidth;
    
    [super setFrame:frame];
    
}
-(void)setIsShowEidt:(BOOL)isShowEidt{
    _isShowEidt=isShowEidt;
    self.editbutton.hidden=!_isShowEidt;
}

-(void)setCarcellmode:(CarlistCellMode *)carcellmode{
    
    _carcellmode=carcellmode;
    self.editbutton.selected=_carcellmode.ischecked;
    CarDetailmodel *cardetail=_carcellmode.cardmode;
    self.titlelable.text=cardetail.car_name;
    self.yanicon.hidden=([cardetail.check_car integerValue]!=2);
    if (![cardetail.truename isEqualToString:@""]&&cardetail.truename) {
        self.shopname.text=cardetail.truename;
    }else if(![cardetail.con_truename isEqualToString:@""]&&cardetail.con_truename){
        self.shopname.text=cardetail.con_truename;
    }else{
        self.shopname.text=cardetail.shop_name;
    }
    
    self.yikoujia.hidden=![cardetail.is_price integerValue]==0;
    if ([cardetail.is_price  integerValue]==2) {
        self.price.text=@"电议";
    }else{
        self.price.text=[NSString stringWithFormat:@"%@万",cardetail.sysprice];
    }

        
    self.time.text=[NSDate dateStrFromTimeStr:cardetail.addtime];
    self.zhidaoprice.hidden=![cardetail.car_source_type isEqualToString:@"中规"];
    if (!self.zhidaoprice.hidden) {
         if ([cardetail.conf_price integerValue]==0||cardetail.conf_price==nil) {
        float xia=[[NSString removeZero:cardetail.sprice] floatValue] - [cardetail.sysprice floatValue];
        
        NSString *strxia=
        [NSString removeZero:[NSString stringWithFormat:@"%.02f",xia]]
        ;
        if (xia>0) {
            if ([cardetail.discount_scale floatValue]!=0) {
                self.zhidaoprice.text=[NSString stringWithFormat:@"指导价:%@万/下%@点",[NSString removeZero:cardetail.sprice],cardetail.discount_scale];
            }else{
            self.zhidaoprice.text=[NSString stringWithFormat:@"指导价：%@万/下%@万",[NSString removeZero:cardetail.sprice],strxia];
            }
        }else if (xia<0)
        {
            NSString *pricestr=[NSString removeZero:[NSString stringWithFormat:@"%.02f",-xia]];
            self.zhidaoprice.text=[NSString stringWithFormat:@"指导价：%@万/上%@万",[NSString removeZero:cardetail.sprice],pricestr];
        }
        
        else{
            self.zhidaoprice.text=[NSString stringWithFormat:@"指导价：%@万",[NSString removeZero:cardetail.sprice]];
        }
        if ([cardetail.is_price integerValue]==2) {
            self.zhidaoprice.text=[NSString stringWithFormat:@"指导价:%@万",[NSString removeZero:cardetail.sprice]];
        }
         }else{
             float xia=[[NSString removeZero:cardetail.conf_price] floatValue] - [cardetail.sysprice floatValue];
             
             NSString *strxia=
             [NSString removeZero:[NSString stringWithFormat:@"%.02f",xia]]
             ;
             if (xia>0) {
                 if ([cardetail.discount_scale floatValue]!=0) {
                     self.zhidaoprice.text=[NSString stringWithFormat:@"配置价:%@万/下%@点",[NSString removeZero:cardetail.conf_price],cardetail.discount_scale];
                 }else{
                     self.zhidaoprice.text=[NSString stringWithFormat:@"配置价:%@万/下%@万",[NSString removeZero:cardetail.conf_price],strxia];
                 }
                
             }else if (xia<0)
             {
                 NSString *pricestr=[NSString removeZero:[NSString stringWithFormat:@"%.02f",-xia]];
                 self.zhidaoprice.text=[NSString stringWithFormat:@"配置价:%@万/上%@万",[NSString removeZero:cardetail.conf_price],pricestr];
             }
             
             else{
                 self.zhidaoprice.text=[NSString stringWithFormat:@"配置价:%@万",[NSString removeZero:cardetail.conf_price]];
             }
             if ([cardetail.is_price integerValue]==2) {
                 self.zhidaoprice.text=[NSString stringWithFormat:@"配置价:%@万",[NSString removeZero:cardetail.conf_price]];
             }

         }
    }
    
    NSString *subtitle=[NSString stringWithFormat:@"%@|%@|%@/%@",cardetail.car_source_type,[cardetail.timer integerValue]==0?@"期货":@"现货",cardetail.car_outside_color,cardetail.car_inside_color];
    if (![cardetail.stock_position isEqualToString:@""]) {
        subtitle=[NSString stringWithFormat:@"%@|%@",subtitle,cardetail.stock_position];
    }
    if (![cardetail.sale_area isEqualToString:@""]) {
        subtitle=[NSString stringWithFormat:@"%@|销%@",subtitle,cardetail.sale_area];
    }
    self.subtitlelable.text=subtitle;
    
    
    
    self.detail.text=cardetail.car_configure;
    
    
    
    
    switch ([cardetail.sale_type integerValue]) {
        case GANGKOU:
            self.shoptypeicon.image=[UIImage imageNamed:@"ico_hk"];
            break;
        case FOURS:
            self.shoptypeicon.image=[UIImage imageNamed:@"ico_4s"];
            break;
        case PERSONAL:
            self.shoptypeicon.image=[UIImage imageNamed:@"ico_p"];
            
            break;
        case ZIYUAN:
            self.shoptypeicon.image=[UIImage imageNamed:@"ico_z"];
            break;
        case ZONGHE:
            self.shoptypeicon.image=[UIImage imageNamed:@"ico_zonghe"];
            break;
        default:
            break;
    }
    
    
    
}


@end
